// 3354. 使数组元素等于零

// int[] nums = { 16, 13, 10, 0, 0, 0, 10, 6, 7, 8, 7 };
// s.CountValidSelections(nums);

public partial class Solution
{
    public int CountValidSelections(int[] nums)
    {
        int res = 0;
        int totalCount = 0;
        foreach (var item in nums)
            totalCount += item;
        int left = 0, curCount = 0;
        while (curCount <= totalCount - curCount + 1 && left < nums.Length)
        {
            curCount += nums[left];
            var delta = Math.Abs(totalCount - 2 * curCount);
            if (nums[left] == 0 && delta <= 1)
                res += 2 - delta;
            left++;
        }

        return res;
    }
}
